<?php
defined('IN_TS') or die('Access Denied.');

include 'groupinfo.php';

$title = $strGroup['groupname'].'_服务记录';


//小组是否需要审核
if($strGroup['isaudit']=='1'){
	//推荐小组
	$arrRecommendGroup = $new['group']->getRecommendGroup('7');
	include template("group_isaudit");

}elseif($strGroup['isopen']=='1' && $isGroupUser=='0'){
	//是否开放访问
	include template("group_isopen");
}else{

	$page = isset($_GET['page']) ? intval($_GET['page']) : 1;

	$lstart = $page*15-15;


	$url = tsUrl('group','duty',array('id'=>$groupid,'page'=>''));

	if($groupid ==1){
		$group = aac('group')->findAll('group',array('isplace'=>1));
		foreach($group as $v){
			$groupids[] = $v['groupid'];
		}
		$groupid1 = implode(',',$groupids);
		$arr = '(groupid=1 or groupid in('.$groupid1.') ) and status>-1';
	}else{
		$arr = "groupid='$groupid' and status>-1 ";
	}

	$arrDutys = $new['group']->findAll('duty',$arr,'addtime desc',null,$lstart.',15');

	if( is_array($arrDutys)){
		foreach($arrDutys as $key=>$item){
			$arrDuty[] = $item;
			$arrDuty[$key]['user'] = aac('user')->getOneUser($item['userid']);
			$arrDuty[$key]['group'] = aac('group')->getOneGroup($item['groupid']);
			if($item['image']){
				$arrDuty[$key]['image'] = explode(',',$item['image']);
			}
			//获取评论
			$arrComments = $new['group']->findAll ( 'duty_comment', array (
				'dutyid' => $item['dutyid']
			), 'addtime desc' );
			//服务类型
			$arrCate= aac('duty')->find('duty_cate',array('cateid'=>$item['cateid']),'catename');
			$arrDuty[$key]['cate'] = $arrCate['catename'];
			foreach ( $arrComments as $k => $v ) {
				$arrDuty[$key]['comment'] [] = $v;
				$arrDuty[$key]['comment'][$k]['content'] = tsDecode($v['content']);
				$arrDuty[$key]['comment'][$k] ['user'] = aac ( 'user' )->getOneUser ( $v ['userid'] );
			}
		}

	}

	$dutyNum = $new['group']->findCount('duty',"`groupid`='$groupid' ".$andType);

	$pageUrl = pagination($dutyNum, 15, $page, $url);


	//小组会员
	include 'groupuser.php';


	if($page > 1){
		$title = $strGroup['groupname'].' - 第'.$page.'页';
	}



	include template("duty");

}